<?php

namespace Common\Model;
use Think\Model;

class ConfigModel extends Model {

  protected $tableName = 'config';

  //TODO::所有内容，缓存化
  /**
   * 获取配置
   */
  public function getAllConfig(){
    $columes = $this->group('type')->getField('type',true);
    $configs = [];
    foreach($columes as $colume){
      $lists = $this->where(['type'=>$colume])->getField('id,name',true);
      $configs[$colume] = $lists;
    }

    return $configs;
  }

  /**
   * 获取医院的配置对应表
   */
  public function getHospitalConfig(){
    $hospitalModel = M('hospital');
    $hospitals = $hospitalModel->select();

    $keshiModel = M('keshi');
    $keshis = $keshiModel->select();

    $hospitalKeshiModel = M('hospitalKeshi');

    foreach ($hospitals as &$hospital) {
      $hospital['keshi_list'] = $hospitalKeshiModel->where(['hospital_id'=>$hospital['id']])->join('LEFT JOIN keshi ON keshi.id=hospital_keshi.keshi_id')->getField('hospital_keshi.id,keshi.name',true);
    }

    return $hospitals;
  }

  /**
   * [getMedicineList description]
   * @return [type] [description]
   */
  public function getMedicineList(){
    $medicineModle = M('aidMedicine');
    $medicines = $medicineModle->select();
    return $medicines;
  }

}